﻿package 
{
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.events.ProgressEvent;
	/**
	 * ...
	 * @author Cain@2009 in ADCAST
	 */
	public class As3 
	{
		static public function geturl(www:String,bn:String = "_blank"):void 
		{
			var url:URLRequest = new URLRequest(www);
			navigateToURL(url, bn);
		}
		static public function clickToURL(mc:DisplayObject,www:String,bn:String  = "_blank"):void 
		{
			mc.addEventListener(MouseEvent.CLICK, mc_click);
			function mc_click(e:MouseEvent):void 
			{
				geturl(www, bn);
			}
		}
		static public function clickToFrame(mc:DisplayObject,_mv:DisplayObject,frame:*):void 
		{
			var mv:MovieClip = _mv as MovieClip;
			mc.addEventListener(MouseEvent.CLICK, mc_click);
			function mc_click(e:MouseEvent):void 
			{
					mv.gotoAndStop(frame);
			}
		}
		static public function loaderIng(mc:Sprite,_url:String,loading_mc:MovieClip):void 
		{
			loading_mc.gotoAndStop(1);
			var url:URLRequest = new URLRequest(_url);
			var loader:Loader = new Loader();
			mc.addChild(loader);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_ok);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loader_ing);
			var n:int;
			loader.load(url);
			function loader_ing(e:ProgressEvent):void 
			{	
				n = Math.floor(e.bytesLoaded / e.bytesTotal * 100);
				loading_mc.gotoAndStop(n);
			}
			function loader_ok(e:Event):void 
			{
				Sprite(loading_mc.parent).removeChild(loading_mc);
			}
		}
		
		static private function loader_ing(e:ProgressEvent):void 
		{
			e.bytesLoaded/e.bytesTotal
		}
	}
	
}